package gui.view;

import gui.controller.SizeChangeListener;

import java.beans.PropertyChangeListener;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;

/**
 * 
 * @author Felix Schliephacke
 * 
 */
public class SizeChoiceBox extends JComboBox {

	private static final long serialVersionUID = 857854616062200269L;
	private SizeChangeListener sizeChangeListener;

	public SizeChoiceBox() {
		super();
		for (int i = 1; i <= 10; i++) {
			this.addItem(i * i + "x" + i * i);
		}
		this.setSelectedIndex(2);
		this.addItemListener(this.getListener());
	}

	public SizeChoiceBox(final ComboBoxModel aModel) {
		super(aModel);
		// TODO Auto-generated constructor stub
	}

	public SizeChoiceBox(final Object[] items) {
		super(items);
		// TODO Auto-generated constructor stub
	}

	public SizeChoiceBox(final Vector<?> items) {
		super(items);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void addPropertyChangeListener(final PropertyChangeListener listener) {
		super.addPropertyChangeListener(listener);
		this.getListener().addPropertyChangeListener(listener);
	}

	private SizeChangeListener getListener() {
		if (this.sizeChangeListener == null) {
			this.sizeChangeListener = new SizeChangeListener(this);
		}
		return this.sizeChangeListener;
	}

	@Override
	public void removePropertyChangeListener(
			final PropertyChangeListener listener) {
		super.removePropertyChangeListener(listener);
		this.getListener().removePropertyChangeListener(listener);
	}

}
